using DbaseInfo;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;

namespace pgImport
{
    public partial class ImportParams : Form
    {
        String[] column_types = {"Text", "Numeric", "Date", "Boolean" };

        private SelectDatabase dbase;
        private Stream import_file;
        private String[] import_data;
        private char separator = ',';

        /// <summary>
        /// Class constructor
        /// </summary>
        /// <param name="selected_dbase">SelectDatabase object encapsulating choosen database details</param>
        /// <param name="import_filestream">Stream object mapped to selected import file</param>
        public ImportParams(SelectDatabase selected_dbase, Stream import_filestream)
        {
            dbase = selected_dbase;
            import_file = import_filestream;

            InitializeComponent();

            // Set controls to their defaults
            PopulateControls();

            // Read the entire import file
            import_data = ReadImportFile();
        }

        // ----------------------------------------------------------------------------------

        #region Event Handlers
        
        /// <summary>
        /// Event handler routine for the 'Accept' button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void acceptButton_Click(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// Event handler for ALL separator buttons
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void separator_CheckedChanged(object sender, EventArgs e)
        {
            // Find out which button is selected ...

                // If 'Other', set separator to entered value
        }
      
        #endregion

        // ----------------------------------------------------------------------------------

        #region Private Members

        /// <summary>
        /// Pre-populates the dialog, setting the controls to their defaults
        /// </summary>
        private void PopulateControls()
        {
            startrowNumericUpDown.Value = 1;
            commaRadioButton.Checked = true;
            otherTextBox.Text = "";

            columntypeComboBox.DataSource = column_types;
        }

        /// <summary>
        /// Read entire import file as array of strings 
        /// </summary>
        /// <returns>An array of strings, consisting the import file</returns>
        private String[] ReadImportFile()
        {
            StreamReader reader = new StreamReader(import_file);
            ArrayList lines = new ArrayList();
            String line;

            // Read line by line ...
            while((line = reader.ReadLine()) != null)
            {
                // ... And append to list
                lines.Add(line);
            }

            // Return list converted back to string array
            return (String[])lines.ToArray(typeof(string));
        }

        #endregion
        
        // ----------------------------------------------------------------------------------
    }
}